package com.zhou.yygh.order.controller.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhou.yygh.common.result.Result;
import com.zhou.yygh.common.utils.AuthContextHolder;
import com.zhou.yygh.order.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zhou.hospital.enums.OrderStatusEnum;
import zhou.hospital.model.order.OrderInfo;
import zhou.hospital.model.user.UserInfo;
import zhou.hospital.vo.order.OrderQueryVo;
import zhou.hospital.vo.user.UserInfoQueryVo;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/order/orderInfo")
@Api(tags = "订单管理")
public class OrderApiController {
    @Autowired
    private OrderService orderService;


    //生成挂号订单
    @PostMapping("/auth/submitOrder/{scheduleId}/{patientId}")
    public Result savaOrders(@PathVariable String scheduleId,
                             @PathVariable Long patientId) {
        Long orderId = orderService.saveOrder(scheduleId,patientId);
        return Result.ok(orderId);
    }

    @GetMapping("/auth/getOrderInfo/{id}")
    public Result getOrderById(@PathVariable Integer id){
        OrderInfo orderInfo = orderService.getOrderInfo(id);
        return Result.ok(orderInfo);
    }

    //条件查询带分页
    @GetMapping("/auth/{page}/{limit}")
    public Result List(@PathVariable Long page,
                       @PathVariable Long limit,
                       OrderQueryVo orderQueryVo,
                       HttpServletRequest request){
        Long userId = AuthContextHolder.getUserId(request);
        orderQueryVo.setUserId(userId);
        Page<OrderInfo> objectPage = new Page<>(page, limit);
       IPage<OrderInfo> pageModel =  orderService.selectPage(objectPage,orderQueryVo);
       return Result.ok(pageModel);
    }


    @ApiOperation("获取订单状态")
    @GetMapping("/auth/getStatusList")
    public Result getStatusList(){
        return Result.ok(OrderStatusEnum.getStatusList());
    }

    @ApiOperation("取消预约")
    @GetMapping("/auth/cancelOrder/{orderId}")

    public  Result canceOrder(@PathVariable Integer orderId){
        orderService.updataOrderStatus(orderId);
        return Result.ok();

    }


}
